package com.example.finance_manager.pages.my;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.finance_manager.R;
import com.example.finance_manager.adapter.ExpendAdapter;
import com.example.finance_manager.dao.PayoutDao;
import com.example.finance_manager.models.Payout;
import com.example.finance_manager.pages.manage.PayoutManageActivity;

import java.io.Serializable;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

public class MyExpendActivity extends AppCompatActivity {
    private ListView lvExpend;
    private List<Payout> payouts = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_expend);

        initView();
        initData();

        ExpendAdapter incomeAdapter = new ExpendAdapter(this, payouts);
        lvExpend.setAdapter(incomeAdapter);

        lvExpend.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(MyExpendActivity.this, PayoutManageActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("payout", (Serializable) payouts.get(i));
                intent.putExtras(bundle);
                startActivity(intent);
                finish();
            }
        });
    }

    private void initView() {
        lvExpend = (ListView) findViewById(R.id.lv_my_expend);
    }

    private void initData() {
        PayoutDao payoutDao = new PayoutDao(MyExpendActivity.this);
        payouts = payoutDao.findAll();
    }
}